package com.crm.dao;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Transaction;

import com.crm.dao.base.BaseHibernateDAO;
import com.crm.po.Config;


public class ConfigDAO extends BaseHibernateDAO {

	private static Logger logger = Logger.getLogger(ConfigDAO.class);

	public void saveOrUpdate(Config config) {
		if(config.getConid() == null || config.getConid().trim().length() == 0){
			config.setConid(this.getUUID());
		}
		Transaction transaction = getSession().beginTransaction();
		try {						
			this.getSession().saveOrUpdate(config);
			transaction.commit();
		} catch (RuntimeException e) {
			transaction.rollback();
			logger.error(e);
		} finally {
			this.closeSession();	
		}
	}

	public Config findById(String id) {
		Config config = null;
		try {
			config = (Config) this.getSession().get(Config.class, id);
		} catch (RuntimeException e) {
			logger.error(e);
		} finally {
			this.closeSession();	
		}
		return config;
	}
	
	@SuppressWarnings("unchecked")
	public List<Config> configList(String hql) {
		return (List<Config>) findList(hql);
	}

}